<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\adminapi\lists\room;


use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsExtendInterface;
use app\common\model\Building;
use app\common\model\Campus;
use app\common\model\room\RoomHospital;
use app\common\lists\ListsSearchInterface;


/**
 * 全院房间管理列表
 * Class RoomHospitalLists
 * @package app\adminapi\listsroom
 */
class RoomHospitalLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface {


    /**
     * @notes 设置搜索条件
     * @return \string[][]
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function setSearch(): array {
        return [
            '=' => ['cid', 'bid', 'status', 'type', 'lift_type'],
            '%like%' => ['name', 'address', 'room_department'],
//            'between_time' => ['add_time', 'device_fee_time'],
        ];
    }


    /**
     * @notes 查询条件
     * @return array
     */
    public function queryWhere() {
        $param = $this->request->param();
        $where = [];

        if (!empty($this->adminCid) && $this->adminCid !== 0) {
            $where[] = ['cid', '=', $this->adminCid];
        }

        if (!empty($param['cb_ids'])) {
            if (!empty($param['cb_ids'][0])) {
                $where[] = ['cid', '=', $param['cb_ids'][0]];
            }
            if (!empty($param['cb_ids'][1])) {
                $where[] = ['bid', '=', $param['cb_ids'][1]];
            }
        }

        return $where;
    }


    /**
     * @notes 获取全院房间管理查询
     */
    public function get_query() {
        return RoomHospital::where($this->searchWhere)
            ->where($this->queryWhere())
            ->with(["campus", "building"]); // , "user"
    }


    /**
     * @notes 获取全院房间管理列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function lists(): array {
        return ($this->get_query())->limit($this->limitOffset, $this->limitLength)->order([
            'sort' => 'asc', 'id' => 'asc'
        ])->append([
            'cb_ids', 'type_text', 'lift_type_text', 'user', "sort",
        ])->select()->toArray();
    }


    /**
     * @notes 获取全院房间管理数量
     * @return int
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function count(): int {
        return ($this->get_query())->count();
    }

    /**
     * @notes 获取扩展
     * @return array
     */
    public function extend() {
        return [];
    }

}
